// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.asm.analysis;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.analysis.AnalyzerException;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.Interpreter;
import org.objectweb.asm.tree.analysis.Value;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
final class FixedFrame extends Frame {

  public FixedFrame(Frame src) {
    super(src);
  }

  public FixedFrame(int locals, int stack) {
    super(locals, stack);
  }

  @Override
  public void execute(AbstractInsnNode insn, Interpreter interpreter) throws AnalyzerException {
    Value value;
    
    switch (insn.getOpcode()) {
      case Opcodes.DUP:
        value = getStack(getStackSize() - 1);
        if (value.getSize() != 1) {
            throw new AnalyzerException("Illegal use of DUP");
        }
        push(interpreter.copyOperation(insn, value));
        break;
      default:
        super.execute(insn, interpreter);
        break;
    }
  }
}
